import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:projectone/search_page.dart';
import './book/list.dart';
import 'drawer_pages.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new FlutterEasyLoading(
        child: new MaterialApp(
      title: '书影在这里',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: '书之影'),
    ));
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }
  @override
  Widget build(BuildContext context) {
    return new DefaultTabController(length: 3, child: Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
        centerTitle: true,
        actions: <Widget>[
          IconButton(onPressed: (){
            //跳转到搜索界面
            Navigator.push(context, MaterialPageRoute(builder: (context){
              return SearchPage();
            }));
          },icon: Icon(Icons.search),)
        ],
      ),
      drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.all(0),
          children: <Widget>[
            UserAccountsDrawerHeader(
              accountEmail: Text('abcdef@example.com',style: TextStyle(color: Colors.indigoAccent),),
              accountName: Text('张三',style: TextStyle(fontWeight: FontWeight.bold),),
              currentAccountPicture:
              CircleAvatar(backgroundImage: NetworkImage
                ('https://gss0.baidu.com/-vo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/b8014a90f603738d7c8316c6b11bb051f919ec0d.jpg'),),
              decoration: BoxDecoration(
                  image: DecorationImage(
                      fit : BoxFit.cover,
                      image: AssetImage('imgs/head_bg.jpg')
                  )
              ),
            ),
            ListTile(title: Text('关于作者'),trailing: Icon(Icons.feedback),onTap: (){
              Navigator.push(context, MaterialPageRoute(builder: (context)=>AboutMePage()));
            },),
            ListTile(title: Text('分享应用'),trailing: Icon(Icons.send),onTap: (){

            },),
            Divider(color: Colors.blue),
            ListTile(title: Text('退出程序'),trailing: Icon(Icons.exit_to_app),onTap: ()=>SystemNavigator.pop(animated: true),),
          ],
        ),
      ),
      bottomNavigationBar: Container(
       decoration: BoxDecoration(color: Colors.cyan),
        height: 50,
        child: TabBar(
          labelStyle: TextStyle(height: 0,fontSize: 10),
          tabs: <Widget>[
            Tab(icon: Icon(Icons.book),text: '书架',),
            Tab(icon: Icon(Icons.chrome_reader_mode),text: '发现',),
            Tab(icon: Icon(Icons.receipt),text: '推荐',),
          ],
        ),
      ),
      body: new TabBarView(children: <Widget>[
        MyBooksPage(),
        BooksList(str:''),
        BookRecommend(),
      ],)// This trailing comma makes auto-formatting nicer for build methods.
    ));
  }

}